class Solution(object):
    def filterRestaurants(self, restaurants, veganFriendly, maxPrice, maxDistance):
        """
        :type restaurants: List[List[int]]
        :type veganFriendly: int
        :type maxPrice: int
        :type maxDistance: int
        :rtype: List[int]
        """

        def filter_rest_fun(restaurant):
            if veganFriendly == 1 and restaurant[2] != 1:
                return False
            return restaurant[3] < maxPrice and restaurant[4] <= maxDistance

        filter_rest = list(filter(filter_rest_fun, restaurants))
        sorted_rest = sorted(filter_rest, key=lambda x: (x[1], x[0]), reverse=True)
        return map(lambda x: x[0], sorted_rest)

